package com.temp.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import com.common.JsonResult;
import com.temp.vo.Talarm;
import com.temp.service.TalarmService;
 
/**
 * 
 * <br>
 * <b>功能：</b>TalarmController<br>
 * <b>作者：</b>suxy<br>
 * <b>日期：</b>2018-7-19 10:44:38 <br>
 * <b>版权所有：
 */ 
@Controller
@RequestMapping("/talarm") 
public class TalarmController {
	
	private final static Logger log= LoggerFactory.getLogger(TalarmController.class);
	
	@Autowired
	private TalarmService talarmService; 
	
	/**
	 * 列表
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/list") 
	public ModelAndView  list(ModelMap model,Talarm talarm) throws Exception{
		List<Talarm> dataList = talarmService.query(talarm);
		Integer total = talarmService.queryTalarmCount(talarm);
		model.put("Talarms", dataList);
		talarm.setTotal(total);
		model.put("talarm", talarm);
		return new ModelAndView("list_Talarm_view");
	}
	
	/**
	 * 添加或修改数据
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public Object save(ModelMap model,Talarm entity) throws Exception{
			if(entity.getId()==null){
				talarmService.insert(entity);
			}else{
				talarmService.update(entity);
			}
		return new ModelAndView(new RedirectView("list.htm"));
	}
	
	@RequestMapping("/getId")
	public Object getId(ModelMap model,Talarm talarm) throws Exception{
		Talarm entity  = talarmService.queryById(talarm);
		model.put("Talarm", entity);
		if("e".equals(talarm.getA())){
			return new ModelAndView("edit_Talarm_view");
		}
		return new ModelAndView("view_Talarm_view");
	}
	
	
	
	@RequestMapping("/delete")
	public Object delete(String id) throws Exception{
		talarmService.delete(id);
		return new JsonResult("删除成功");
	}

	@InitBinder  
   protected void initBinder(WebDataBinder binder) {  
		 binder.registerCustomEditor(Date.class, new CustomDateEditor(
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));  
   } 
   
}
